/*
 * Copyright 2006-2022 ahtelit.com, All Rights Reserved.
 */

package com.telit.android.feign.factory;

import com.telit.android.entity.AppUserLocation;
import com.telit.android.feign.RemoteAndroidService;
import com.telit.common.entity.AppTask;
import com.telit.common.entity.CommEventTaskTrack;
import com.telit.common.entity.DataReturn;
import com.telit.common.enums.ResultCode;
import com.telit.common.util.LanguageUtils;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * RemoteAndroidServiceFallbackFactory
 *
 * @author yuezhuang
 * @since 2022-12-14
 */
@Slf4j
@Component
public class RemoteAndroidServiceFallbackFactory implements FallbackFactory<RemoteAndroidService> {

    @Override
    public RemoteAndroidService create(Throwable cause) {
        return new RemoteAndroidService() {
            /**
             * 标准化输出微服务内部调用错误信息
             *
             * @return DataReturn
             */
            private DataReturn defaultFallback() {
                String msg = LanguageUtils.codeMessage(ResultCode.SERVER_FEIGN_ERROR.getCode(), cause.getMessage());
                log.error(msg, cause);
                return DataReturn.failure(ResultCode.SERVER_FEIGN_ERROR.getCode(), msg);
            }

            @Override
            public DataReturn findTaskingByUserIdPost(List<Long> foresterIdList) {
                return defaultFallback();
            }

            @Override
            public DataReturn searchNoPageForFeign() {
                return defaultFallback();
            }

            @Override
            public DataReturn findById(Long id) {
                return defaultFallback();
            }

            @Override
            public DataReturn findTyeByIds(List<Long> ids) {
                return defaultFallback();
            }

            @Override
            public DataReturn selectSimpleDataByUserIds(List<Long> userIdList) {
                return defaultFallback();
            }

            @Override
            public DataReturn updateCommEventTaskTrackByParam(CommEventTaskTrack commEventTaskTrack) {
                return defaultFallback();
            }

            @Override
            public DataReturn updateAppTaskByParam(AppTask appTask) {
                return defaultFallback();
            }

            @Override
            public DataReturn selectIdByTaskIdAndStatus(Long taskId, String status, Long forestkeeperId) {
                return defaultFallback();
            }

            @Override
            public DataReturn<List<AppUserLocation>> onlineList() {
                return defaultFallback();
            }
        };
    }

}
